// 
// Copyright 2010 Classpath Pty Ltd <opensource@classpath.com.au>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 

using build

**
** Tests the `MigrationZero` migration.
**
internal class MigrationZeroTest : Test {

    **
    ** Stores an instance of `MigrationZero` for testing.
    **
    MigrationZero? migrationZero

    **
    ** Performs additional setup needed for `MigrationZeroTest`.
    **
    override Void setup() {
        super.setup()
        migrationZero = MigrationZero()
    }

    **
    ** Cleans up additional setup needed for `MigrationZeroTest`.
    **
    override Void teardown() {
        super.teardown()
        migrationZero = null
    }

    **
    ** Tests the `MigrationZero.up` method.
    **
    Void testUp() {
        migrationZero.up
        verifyEq(1, migrationZero.modifications.size)
        verifyEq(CreatedTable#, migrationZero.modifications[0].typeof)
        table := migrationZero.modifications[0] as CreatedTable
        verifyEq(MigrationZero.tableName, table.name)
        verifyEq(4, table.modifications.size)
        table.modifications.each |CreatedColumn column, Int i| {
            switch (i)
            {
                case 0:
                    verifyEq(MigrationZero.idColumnName, column.name)
                    verifyEq(3, column.modifications.size)
                    verifyEq(AutoIncrementColumnOption#, column.modifications[0].typeof)
                    verifyEq(CommentColumnOption#, column.modifications[1].typeof)
                    verifyEq("The ID of the migration", (column.modifications[1] as CommentColumnOption).comment)
                    verifyEq(PrimaryKeyColumnOption#, column.modifications[2].typeof)
                case 1:
                    verifyEq(MigrationZero.timestampColumnName, column.name)
                    verifyEq(3, column.modifications.size)
                    verifyEq(CommentColumnOption#, column.modifications[0].typeof)
                    verifyEq("The timestamp of the migration", (column.modifications[0] as CommentColumnOption).comment)
                    verifyEq(DefaultValueColumnOption#, column.modifications[1].typeof)
                    verifyEq("NOW()", (column.modifications[1] as DefaultValueColumnOption).defaultValue)
                    verifyEq(NotNullColumnOption#, column.modifications[2].typeof)
                case 2:
                    verifyEq(MigrationZero.fromVersionColumnName, column.name)
                    verifyEq(2, column.modifications.size)
                    verifyEq(CommentColumnOption#, column.modifications[0].typeof)
                    verifyEq("The version being migrated from", (column.modifications[0] as CommentColumnOption).comment)
                    verifyEq(NotNullColumnOption#, column.modifications[1].typeof)
                case 3:
                    verifyEq(MigrationZero.toVersionColumnName, column.name)
                    verifyEq(2, column.modifications.size)
                    verifyEq(CommentColumnOption#, column.modifications[0].typeof)
                    verifyEq("The version being migrated to", (column.modifications[0] as CommentColumnOption).comment)
                    verifyEq(NotNullColumnOption#, column.modifications[1].typeof)
                default:
                    fail
            }
        }
    }

    **
    ** Tests the `MigrationZero.down` method.
    **
    Void testDown() {
        migrationZero.down
        verifyEq(1, migrationZero.modifications.size)
        verifyEq(DroppedTable#, migrationZero.modifications[0].typeof)
        table := migrationZero.modifications[0] as DroppedTable
        verifyEq(MigrationZero.tableName, table.name)
    }

}
